package com.example.interview.clone;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-04-01
 * Time:21:10
 * Text：深克隆实现一：引用属性实现克隆
 */
class Teacher2  implements Cloneable{
    private String name;
    private  int age;
    private Student2 student;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student2 getStudent() {
        return student;
    }

    public void setStudent(Student2 student) {
        this.student = student;
    }

    @Override
    protected Teacher2 clone(){
        Teacher2 t1 = null;
        try {
            t1 = (Teacher2) super.clone();
            // 克隆引用类型
            t1.setStudent(t1.getStudent().clone());
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        return t1;
    }
}
class Student2  implements Cloneable{
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Student2 clone()  {
        Student2 student2 = null;
        try {
            super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        return student2;
    }
}
public class Deep_Clone {

}
